<!DOCTYPE html>
<html lang="en">
<head>
	<title>集中管控平台</title>
	<meta charset="utf-8">
	<meta name="format-detection" content="telephone=no">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<link rel="stylesheet" type="text/css" href="css/login.css">
</head>
<body class="bg">
	<div class="login-box">
		<div class="logo-box">
			<img class="logo" src="img/login/syslogo.png">
			<p>欢迎来到信大捷安集中管控管理平台</p>
		</div>
		<input class="form-control login-input" placeholder="账号" type="text" name="username" id="username">
		<input class="form-control login-input" placeholder="密码" type="password" name="pwd" id="pwd">
		<div class="login-identify">
			<input class="login-input" type="text" placeholder="验证码" name="identify" id="identify">
			<div class="vertify" id="gVerify"></div>
		</div>
		<a class="login-btn">登录平台</a>
	</div>
	<script src='./js/ip.js'></script>
	<script type="text/javascript" src="./js/lib/jquery/jquery.1.10.2.js"></script>
	<script src='js/lib/jquery.placeholder.js'></script>
	<script type="text/javascript" src="./js/plugin/layer/layer.js"></script>
	<script type="text/javascript" src="./js/plugin/gVerify/gVerify.js"></script>
	<script type="text/javascript">
	 $('input[placeholder]').placeholder();
	 $('#username').focus();
		// 初始化验证码
		var verifyCode = new GVerify({
			id: 'gVerify',
			type: 'number'
		});
		// 点击登录
		$('.login-btn').on('click', function () {
			var username = $.trim($('#username').val());
			var pwd = $.trim($('#pwd').val());
			if (!username) {
				layer.msg('请输入用户名！');
				return false;
			} else if (!pwd){
				layer.msg('请输入密码！');
				return false;
			} else {
				if (!$.trim($('#identify').val())) {
					layer.msg('请输入验证码！');
				} else {
					if (verifyCode.validate($('#identify').val())) {
						$.ajax({
							// url: index_web_app + index_xd_prefix + 'api/public/login',
							url:  'api/public/login',
							type: 'post',
							data: JSON.stringify({
								username: username,
								password: pwd
							}),
							dataType: 'json',
							contentType: 'application/json',
							success: function (data) {
								if (data.code == 1) {
									sessionStorage.setItem('token', data.result);
									sessionStorage.setItem('username',username);
									location.href = 'index.html';
								} else {
									$('#pwd, #identify').val('');
									verifyCode.refresh();
									layer.msg(data.message);
								}
							}
						});
					} else {
						layer.msg('验证码错误，请重新输入！');
							$('#identify').val('');
					}
				}
			}
		});

		// 回车登录事件
		$(document).keyup(function(e){
			if(e.keyCode == 13){
			  $('.login-btn').trigger('click'); //处理事件
			}
		});
	</script>
</body>
</html>